layui.use(['table', 'admin', 'ax','laydate','element'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var laydate = layui.laydate;
	var element = layui.element
	
	//tab切换
	element.on('tab(doTabBrief)',function(data){
		console.log(data.index)
	})

    laydate.render({
      elem: '#startTime'
        	,value:new Date()
    });

    laydate.render({
      elem: '#endTime'
        	,value:new Date()
    });

    /**
     * 期间库容统计管理
     */
    var StoragePeriod = {
        tableId: "storagePeriodTable"
    };

    /**
     * 期间库容统计管理
     */
    var StoragePeriod2 = {
        tableId: "storagePeriodTable2"
    };

    /**
     * 初始化表格的列
     */
    StoragePeriod.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, title: '主键'},
            {field: 'operateName', sort: true, title: '项目'},
            {field: 'customerName', sort: true, title: '客户'},
            {field: 'warehouseName', sort: true, title: '仓库'},
            {field: 'dates', sort: true, title: '日期', totalRowText: '合计：'},
            {field: 'qcNum', sort: true, title: '期初库存数', totalRow: true},
            {field: 'qcVolume', sort: true, title: '期初体积', totalRow: true},
            {field: 'qcWeight', sort: true, title: '期初重量', totalRow: true},
            {field: 'qcMoney', sort: true, title: '期初金额', totalRow: true},

            {field: 'kwshu', sort: true, title: '已用库位数', totalRow: true},
            {field: 'putNum', sort: true, title: '入库库存数', totalRow: true},
            {field: 'putVolume', sort: true, title: '入库体积', totalRow: true},
            {field: 'putWeight', sort: true, title: '入库重量', totalRow: true},
            {field: 'putMoney', sort: true, title: '入库金额', totalRow: true},

            {field: 'outNum', sort: true, title: '出库库存数', totalRow: true},
            {field: 'outVolume', sort: true, title: '出库体积', totalRow: true},
            {field: 'outWeight', sort: true, title: '出库重量', totalRow: true},
            {field: 'outMoney', sort: true, title: '出库金额', totalRow: true},

            {field: 'qmNum', sort: true, title: '期末库存数', totalRow: true},
            {field: 'qmVolume', sort: true, title: '期末体积', totalRow: true},
            {field: 'qmWeight', sort: true, title: '期末重量', totalRow: true},
            {field: 'qmMoney', sort: true, title: '期末金额', totalRow: true},
        ]];
    };

    /**
     * 初始化表格的列
     */
    StoragePeriod2.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, title: '主键'},
            {field: 'warehouseName', sort: true, title: '仓库', totalRowText: '合计：'},
            {field: 'sumP', sort: true, title: '总库位数', totalRow: true},
            {field: 'ksumP', sort: true, title: '空库位数', totalRow: true},
            {field: 'ysumP', sort: true, title: '已使用库位数', totalRow: true},

            {field: 'sumPt', sort: true, title: '总可存托数', totalRow: true},
            {field: 'dsumPt', sort: true, title: '剩余可存托数', totalRow: true},
            {field: 'ysumPt', sort: true, title: '已存托数', totalRow: true},
        ]];
    };

    /**
     * 点击查询按钮
     */
    StoragePeriod.search = function () {
        var queryData = {};
        queryData['startTime'] = $("#startTime").val();
        queryData['endTime'] = $("#endTime").val();
        queryData['operateId'] = $("#operateId").val();
        queryData['customerId'] = $("#customerId").val();
        queryData['warehouseId'] = $("#warehouseId").val();
        table.reload(StoragePeriod.tableId, {
            where: queryData, page: {curr: 1},
             done:function () {
            }
        });
    };

    /**
     * 点击查询按钮
     */
    StoragePeriod2.search = function () {
        var queryData = {};
        queryData['id'] = $("#warehouseId2").val();
        queryData['customerId'] = $("#customerId2").val();
        table.reload(StoragePeriod2.tableId, {
            where: queryData, page: {curr: 1},
             done:function () {
            }
        });
    };

    /**
     * 导出excel按钮
     */
    StoragePeriod.exportExcel = function () {
        var checkRows = table.checkStatus(StoragePeriod.tableId);
        if (checkRows.data.length === 0) {
            Feng.error("请选择要导出的数据");
        } else {
            table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        }
    };

    /**
     * 导出excel按钮
     */
    StoragePeriod2.exportExcel = function () {
        var checkRows = table.checkStatus(StoragePeriod2.tableId);
        if (checkRows.data.length === 0) {
            Feng.error("请选择要导出的数据");
        } else {
            table.exportFile(tableResult2.config.id, checkRows.data, 'xls');
        }
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + StoragePeriod.tableId,
        url: Feng.ctxPath + '/storagePeriod/list',
        page: true,
        limit: 60,
		limits:[60,120,240,360,480,1500,5000],
        height: "full-60",
        toolbar: '#toolbarfrom',
        totalRow: true ,//开启合计行
        cellMinWidth: 100,
        cols: StoragePeriod.initColumn()
    });

    // 渲染表格
    var tableResult2 = table.render({
        elem: '#' + StoragePeriod2.tableId,
        url: Feng.ctxPath + '/basicWarehouse/Storagelist',
        page: false,
        limit: 120,
		limits:[60,120,240,360,480,1500,5000],
        height: "full-60",
        toolbar: '#toolbarfrom',
        totalRow: true ,//开启合计行
        cellMinWidth: 100,
        cols: StoragePeriod2.initColumn()
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        StoragePeriod.search();
    });

    // 搜索按钮点击事件
    $('#btnSearch2').click(function () {
        StoragePeriod2.search();
    });

    // 导出excel
    $('#btnExp').click(function () {
        StoragePeriod.exportExcel();
    });

    // 导出excel
    $('#btnExp2').click(function () {
        StoragePeriod2.exportExcel();
    });

});
